
const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    users:[]

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
  toHide:function (all) {
   
    let mphone = all.substring(0, 3) + '****' + all.substring(7);
    return mphone;
},
  save: function(e) {
   let openId = wx.getStorageSync('openId');
    let str = e.detail.value;
    str.phone = this.toHide(str.phone);
   let nameLen = e.detail.value.name.length;
    let numLen = e.detail.value.phone.length;
    if(numLen == 0){
      wx.showToast({
        title: '请输入手机号',
        icon:'none'
      })
    }
   else if(numLen != 11||nameLen > 6){
      wx.showToast({
        title: '手机号位数不对或名字过长',
        icon:'none'
      })
    }else{
      db.collection('users').where({
        _openid:openId
      }).update({
        data:{
        name:e.detail.value.name,
        baovoice:e.detail.value.phone
        }
      });
       wx.setStorageSync('name',e.detail.value.name);
       wx.setStorageSync('phone',e.detail.value.phone);
      let arr = [];
      arr.push(str);
      let pages = getCurrentPages(); //获取当前页面
      let beforePage = pages[pages.length - 2]; //获取上一个页面的实例  
      //修改上一个页面的响应式数据
      beforePage.setData({
        store: arr
      })
      wx.showToast({
        title: '更新成功',
        duration: 1000,
        icon: 'success'
      })
      setTimeout(() => {
        wx.navigateBack({
          delta: 1
        })
      }, 1000)

      }  
  },


})